package com.fx.service.impl;

import cn.hutool.core.date.DateUtil;
import com.fx.entity.AdInfo;
import com.fx.entity.AdminTempUser;
import com.fx.mapper.AdInfoMapper;
import com.fx.service.AdInfoService;
import com.fx.util.IdWorker;
import org.apache.shiro.SecurityUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;


@Service
public class AdInfoServiceImpl implements AdInfoService {
    @Autowired
    private AdInfoMapper adInfoMapper;
    @Autowired
    private IdWorker idWorker;

    @Override
    public AdInfo getById(String flId) {
        return adInfoMapper.getById(flId);
    }

    @Override
    public List<AdInfo> getList(Map<String, Object> map) {
        return adInfoMapper.queryList(map);
    }

    @Override
    public int getCount(Map<String, Object> map) {
        return adInfoMapper.queryCount(map);
    }

    @Override
    public int save(AdInfo adInfo) {
        adInfo.setFlId(String.valueOf(idWorker.nextId()));
        adInfo.setFlCreatedTime(DateUtil.now());
        adInfo.setFlCreator(((AdminTempUser) SecurityUtils.getSubject().getPrincipal()).getFlName());
        return adInfoMapper.save(adInfo);
    }

    @Override
    public int updateById(AdInfo adInfo) {
        return adInfoMapper.updateById(adInfo);
    }

    @Override
    public int remove(String flId) {
        return adInfoMapper.remove(flId);
    }

    @Override
    public int batchRemove(String[] flIds) {
        return adInfoMapper.batchRemove(flIds);
    }

    @Override
    public List<AdInfo> getAdByLocation(Map<String, Object> param) {
        return adInfoMapper.queryByLocation(param);
    }

}
